Python: Select Foundry hosting conversation history source - #7997
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a4c73599-9f66-4c22-bd66-96fe676e0ce6
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a4c73599-9f66-4c22-bd66-96fe676e0ce6
There was a problem hiding this comment.
Pull request overview
Adds explicit model-history ownership for Python Foundry-hosted response agents, preventing duplicated conversation replay.
Changes:
- Adds
agent_serverandagenthistory-source modes. - Enforces stateless downstream calls in AgentServer mode.
- Adds regression tests, documentation, and ADR 0039.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
_responses.py |
Implements history-source selection and storage safeguards. |
test_responses.py |
Covers history modes and session persistence. |
README.md |
Documents configuration and behavior. |
0039-python-foundry-hosting-history-source.md |
Records the architectural decision. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): a6ea50e3ab2e
Model: gpt-5.6-sol
Overview
The PR makes model-history ownership explicit and adds strong guards for standard Agent instances: it rejects conflicting providers and defaults, forces downstream storage off, clears stale service IDs, and tests persistence and function-loop behavior. Two gaps remain around the broader SupportsAgentRun contract and reuse of the caller-owned agent: mandatory storage options can be dropped for custom agents, and the transient provider installed by the default mode survives a later switch to agent-managed history.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (2 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a4c73599-9f66-4c22-bd66-96fe676e0ce6
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a4c73599-9f66-4c22-bd66-96fe676e0ce6
|
Reporter of #7955 — ran my repro/upgrade benches from that thread against this branch (default One gap in ADR 0039, though: the
|
|
Sachin Kahawala (@sachinkahawala) I reported that issue and they are looking into it, and in the meantime consider non-streaming, or indeed use the agent history. The agent history is not meant as a fix for that issue, however it does, it is meant for folks who want to 1) leverage the storage provided by the underlying service (for instance if you want to use OpenAI for the conversation storage, so your internal agent runs against that with store=True), and 2) people who want to use a HistoryProvider to store the history in their own storage mechanism, and this can be the case for all sorts of reasons, like compliance, etc. So the key is to change the authority and management of the history, not to fix the latency. |
There was a problem hiding this comment.
MAF Automated Review — Iteration 2
Result: Findings reported
Scope: 3 net-new commit(s): 98c216ce5d8b, a77eeb50b4a8, 5713d33ca739
Model: gpt-5.6-sol-fast
Overview
The incremental change distinguishes clients that store by default, preserves the host-owned store=False directive when request options are ignored, and adds focused unit and Foundry integration coverage for both history modes. Existing guards reject conflicting history providers, clear restored service IDs, discard transient history state, and refuse to persist detected downstream-storage violations. Two residual lifecycle and protocol-compatibility defects remain: generic custom agents can receive an unsupported keyword, and failed server construction can leave the caller's agent mutated.
Reviewed the supplied incremental change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (2 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a4c73599-9f66-4c22-bd66-96fe676e0ce6
Motivation & Context
Foundry-hosted Responses agents can restore a downstream service conversation ID while also replaying the complete AgentServer response transcript. The model then receives duplicated history, and the duplication compounds on each turn. Always requiring AgentServer history avoids competing sources, but prevents applications from choosing service, session-backed, or external history storage needed for compliance, residency, retention, deletion, encryption, and audit requirements.
This change makes the model-history source explicit while retaining AgentServer response persistence and session storage as independent concerns.
Description & Review Guide
history_source="agent_server" | "agent"toResponsesHostServer. The default AgentServer mode requires aRawAgentclient with theSTORES_BY_DEFAULTcapability, replays response-provider history, disables downstream storage only for clients that store by default, removes unsupported storage options for other clients, clears stale service IDs, rejects all conflicting continuation aliases, and refuses to persist a session if a client still stores downstream. Agent mode passes only current request input, supports customSupportsAgentRunimplementations without forwarding unsupported chat options, and preserves normalAgenthistory-provider and service-storage behavior. Constructor validation completes before the host mutates its owned agent. The PR also adds unit and real Foundry integration coverage, package documentation, and ADR 0039 with the considered alternatives.InMemoryHistoryProviderpersisted throughFoundryAgentSessionStore, an external history provider, or a custom agent can explicitly selecthistory_source="agent".Related Issue
Fixes #7955
The earlier PR #7957 was closed unmerged for design discussion; there is no other open PR for this issue.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and the title prefix in sync automatically.